import pinyin from "js-pinyin";
import { user } from "@/api";
import store from "../store";

// 中文转英文
function cPinyin(chinese) {
    // 你好 => NH
    return pinyin.getCamelChars(chinese);
}

function auth(num) {
    let authList = store.state.userInfo.auth;

    return authList.some((item) => item === num);
}

// 保存我的用户信息
function UserInfo() {
    user().then((res) => {
        // 存入用户信息
        localStorage.setItem("identity", res.data.roles);
        const auth = {
            ...res.data,
            auth: res.data.auth.split(","),
        };
        store.commit("save_userInfo", auth);
        store.commit("save_userId", res.data.id);
    });
}

export { cPinyin, UserInfo, auth };